{
  "metadata": {
    "kernelspec": {
      "name": "SQLite",
      "display_name": "SQLite",
      "language": "sql"
    },
    "language_info": {
      "file_extension": ".sqlite3-console",
      "mimetype": "text/x-sqlite3-console",
      "name": "sqlite3",
      "version": "0.4.0"
    }
  },
  "nbformat_minor": 4,
  "nbformat": 4,
  "cells": [
    {
      "cell_type": "markdown",
      "source": "# JupyterLite `xeus-sqlite` Kernel Demo\n\nThe [`jupyterlite/xeus-sqlite-kernel`](https://github.com/jupyterlite/xeus-sqlite-kernel) wraps the original [`jupyter-xeus/xeus-sqlite`](https://github.com/jupyter-xeus/xeus-sqlite/) kernel for use in JupyterLite.\n\nOriginal kernel docs can be found [here](https://xeus-sqlite.readthedocs.io/en/latest/).\n\nThe kernel provides cell magic for command line database operations, and native execution of SQL code against a connected database.",
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": "## Creating a Database\n\nLine magic is used to create an in-memory database:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "%CREATE example_db.db",
      "metadata": {
        "trusted": true
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": "Currently, there is no ability to:\n\n- save the database to browser storage;\n- export the database;\n- load a database from browser storage;\n- load a database from a URL;\n- load a database from the desktop;\n- connect to a remote sqlite database file.",
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": "## Create and Populate Tables\n\nTables are created and populated using SQL:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "CREATE TABLE players (Name STRING, Class STRING, Level INTEGER, Hitpoints INTEGER)",
      "metadata": {
        "trusted": true
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "INSERT INTO players (Name, Class, Level, Hitpoints) VALUES (\"Martin Splitskull\", \"Warrior\", 3, 40)",
      "metadata": {
        "trusted": true
      },
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "SELECT COUNT(*) as rowcount FROM players",
      "metadata": {
        "trusted": true
      },
      "execution_count": 4,
      "outputs": [
        {
          "execution_count": 4,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>rowcount</th>\n</tr>\n<tr>\n<td>1</td>\n</tr>\n</table>",
            "text/plain": "+----------+\n| rowcount |\n+----------+\n| 1        |\n+----------+"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "Only one command can be executed from within a single code cell:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "INSERT INTO players (Name, Class, Level, Hitpoints) VALUES (\"Sir Wolf\", \"Cleric\", 2, 20);\n\n-- The following will not be inserted\nINSERT INTO players (Name, Class, Level, Hitpoints) VALUES (\"Sylvain, The Grey\", \"Wizard\", 1, 10);",
      "metadata": {
        "trusted": true
      },
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "SELECT Name, Level, Hitpoints FROM players;",
      "metadata": {
        "trusted": true
      },
      "execution_count": 6,
      "outputs": [
        {
          "execution_count": 6,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>Name</th>\n<th>Level</th>\n<th>Hitpoints</th>\n</tr>\n<tr>\n<td>Martin Splitskull</td>\n<td>3</td>\n<td>40</td>\n</tr>\n<tr>\n<td>Sir Wolf</td>\n<td>2</td>\n<td>20</td>\n</tr>\n</table>",
            "text/plain": "+-------------------+-------+-----------+\n| Name              | Level | Hitpoints |\n+-------------------+-------+-----------+\n| Martin Splitskull | 3     | 40        |\n+-------------------+-------+-----------+\n| Sir Wolf          | 2     | 20        |\n+-------------------+-------+-----------+"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": "INSERT INTO players (Name, Class, Level, Hitpoints) VALUES (\"Sylvain, The Grey\", \"Wizard\", 1, 10);",
      "metadata": {
        "trusted": true
      },
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "SELECT Name, Level, Hitpoints FROM players;",
      "metadata": {
        "trusted": true
      },
      "execution_count": 8,
      "outputs": [
        {
          "execution_count": 8,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>Name</th>\n<th>Level</th>\n<th>Hitpoints</th>\n</tr>\n<tr>\n<td>Martin Splitskull</td>\n<td>3</td>\n<td>40</td>\n</tr>\n<tr>\n<td>Sir Wolf</td>\n<td>2</td>\n<td>20</td>\n</tr>\n<tr>\n<td>Sylvain, The Grey</td>\n<td>1</td>\n<td>10</td>\n</tr>\n</table>",
            "text/plain": "+-------------------+-------+-----------+\n| Name              | Level | Hitpoints |\n+-------------------+-------+-----------+\n| Martin Splitskull | 3     | 40        |\n+-------------------+-------+-----------+\n| Sir Wolf          | 2     | 20        |\n+-------------------+-------+-----------+\n| Sylvain, The Grey | 1     | 10        |\n+-------------------+-------+-----------+"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "## Quuerying Tables\n\nA full range of SQL query commands are supported, including aggregation operations:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "SELECT SUM (Level) FROM players",
      "metadata": {
        "trusted": true
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": "Grouping also works:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "SELECT Level, SUM(Hitpoints) AS `Total Hitpoints`\nFROM players\nGROUP BY Level\nORDER BY `Total Hitpoints` DESC;",
      "metadata": {
        "trusted": true
      },
      "execution_count": 11,
      "outputs": [
        {
          "execution_count": 11,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>Level</th>\n<th>Total Hitpoints</th>\n</tr>\n<tr>\n<td>3</td>\n<td>40</td>\n</tr>\n<tr>\n<td>2</td>\n<td>20</td>\n</tr>\n<tr>\n<td>1</td>\n<td>10</td>\n</tr>\n</table>",
            "text/plain": "+-------+-----------------+\n| Level | Total Hitpoints |\n+-------+-----------------+\n| 3     | 40              |\n+-------+-----------------+\n| 2     | 20              |\n+-------+-----------------+\n| 1     | 10              |\n+-------+-----------------+"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "## Charting Using Vega\n\nThe `jupyter-xeus/xeus-sqlite` kernel also bundles Vega charting components.\n\nVega charts can be generated by piping the result of a SQL query into a Vega line magic command.",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "%XVEGA_PLOT\n    X_FIELD Level\n    Y_FIELD Hitpoints\n    MARK circle\n    WIDTH 100\n    HEIGHT 200\n    <>\n    SELECT Level, Hitpoints FROM players",
      "metadata": {
        "trusted": true
      },
      "execution_count": 12,
      "outputs": [
        {
          "execution_count": 12,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>Level</th>\n<th>Hitpoints</th>\n</tr>\n<tr>\n<td>3</td>\n<td>40</td>\n</tr>\n<tr>\n<td>2</td>\n<td>20</td>\n</tr>\n<tr>\n<td>1</td>\n<td>10</td>\n</tr>\n</table>",
            "text/plain": "+-------+-----------+\n| Level | Hitpoints |\n+-------+-----------+\n| 3     | 40        |\n+-------+-----------+\n| 2     | 20        |\n+-------+-----------+\n| 1     | 10        |\n+-------+-----------+"
          },
          "metadata": {}
        },
        {
          "execution_count": 12,
          "output_type": "execute_result",
          "data": {
            "application/vnd.vegalite.v3+json": {
              "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
              "config": {
                "axis": {
                  "grid": true
                }
              },
              "data": {
                "values": [
                  {
                    "Hitpoints": "name",
                    "Level": "name"
                  },
                  {
                    "Hitpoints": "40",
                    "Level": "3"
                  },
                  {
                    "Hitpoints": "20",
                    "Level": "2"
                  },
                  {
                    "Hitpoints": "10",
                    "Level": "1"
                  }
                ]
              },
              "encoding": {
                "x": {
                  "field": "Level",
                  "type": "quantitative"
                },
                "y": {
                  "field": "Hitpoints",
                  "type": "quantitative"
                }
              },
              "height": 200,
              "mark": {
                "type": "circle"
              },
              "width": 100
            },
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJMAAAD3CAYAAAAZgGZZAAAAAXNSR0IArs4c6QA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kJP8zFac4b6TCYswumqKgo9TSdG7sOz3P4tMYwvfLKKzRz5kz1/7/55hvil04bNmyoYvv27Uu8EuLSpUtUu3Ztat68OX3xxRe0atUqSkxMpA0bNtAzzzwDmAyOi1eGu2AqmDyvPeLF/rxU5cKFC2r+xAvMnnzySRXKa7ASEhLUqY5Pcdz4FkN0dLRaSclt1qxZ9NZbb6k5Fm4NeCUe5ibNb7WcPXuWGjRooJxJp3F8nTp1yvR1Kp08pRjcGpAUws+1FQBM2lIhUFIAMEkK4efaCgAmbakQKCkAmCSF8HNtBf4PeeHBOWN20+UAAAAASUVORK5CYII="
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "## Database Admininstration\n\nSeveral line magics are defined to support database administration",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "%TABLE_EXISTS players",
      "metadata": {
        "trusted": true
      },
      "execution_count": 15,
      "outputs": [
        {
          "execution_count": 15,
          "output_type": "execute_result",
          "data": {
            "text/plain": "The table players exists."
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": "%TABLE_EXISTS npcs",
      "metadata": {
        "trusted": true
      },
      "execution_count": 16,
      "outputs": [
        {
          "execution_count": 16,
          "output_type": "execute_result",
          "data": {
            "text/plain": "The table npcs doesn't exist."
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": "%GET_INFO",
      "metadata": {
        "trusted": true
      },
      "execution_count": 17,
      "outputs": [
        {
          "execution_count": 17,
          "output_type": "execute_result",
          "data": {
            "text/plain": "Magic header string: SQLite format 3\nPage size bytes: 4096\nFile format write version: 1\nFile format read version: 1\nReserved space bytes: 0\nMax embedded payload fraction 64\nMin embedded payload fraction: 32\nLeaf payload fraction: 32\nFile change counter: 4\nDatabase size pages: 2\nFirst freelist trunk page: 0\nTotal freelist trunk pages: 0\nSchema cookie: 1\nSchema format number: 4\nDefault page cache size bytes: 0\nLargest B tree page number: 0\nDatabase text encoding: 1\nUser version: 0\nIncremental vaccum mode: 0\nApplication ID: 0\nVersion valid for: 4\nSQLite version: 3032003\n"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "## Connecting to a Different Databases\n\nCreating a new database will connect the kernel to the new database instance.",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "%CREATE potato.db ",
      "metadata": {
        "trusted": true
      },
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "CREATE TABLE potaters(production INTEGER)",
      "metadata": {
        "trusted": true
      },
      "execution_count": 19,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "INSERT INTO potaters (production) VALUES (7)",
      "metadata": {
        "trusted": true
      },
      "execution_count": 20,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "SELECT * FROM potaters",
      "metadata": {
        "trusted": true
      },
      "execution_count": 21,
      "outputs": [
        {
          "execution_count": 21,
          "output_type": "execute_result",
          "data": {
            "text/html": "<table>\n<tr>\n<th>production</th>\n</tr>\n<tr>\n<td>7</td>\n</tr>\n</table>",
            "text/plain": "+------------+\n| production |\n+------------+\n| 7          |\n+------------+"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": "The original database is lost:",
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": "SELECT Name, Level, Hitpoints FROM players;",
      "metadata": {
        "trusted": true
      },
      "execution_count": 23,
      "outputs": [
        {
          "ename": "Error",
          "evalue": "no such table: players",
          "traceback": [
            "Error: no such table: players"
          ],
          "output_type": "error"
        }
      ]
    }
  ]
}